package com.my.study.algorithm;

/**
 * 大数相加
 * 
 * @author Carlos
 * @version 1.0.0
 * @date 2023/3/26 12:11
 */
public class BigAdd {

    public static void main(String[] args) {
        
        
        
    }
    
    
    private String bigAdd(String numOne, String numTwo) {
        StringBuilder sb = new StringBuilder();
        // 进位
        int carry = 0;
        char[] charsOne = numOne.toCharArray();
        char[] charsTwo = numTwo.toCharArray();
        int oneEndIndex = charsOne.length - 1;
        int tweEndIndex = charsTwo.length - 2;
        
        while (oneEndIndex >= 0 || tweEndIndex >= 0 || carry > 0) {
            int v1 = oneEndIndex < 0 ? 0 : charsOne[oneEndIndex--] - '0';
            int v2 = tweEndIndex < 0 ? 0 : charsTwo[tweEndIndex--] - '0';
            int sum = v1 + v2 + carry;
            sb.insert(0, sum % 10);
            carry = sum / 10;
        }

        return sb.toString();
    }
}
